using System;
using System.Reflection;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using SpiritEngine;
using SpiritEngine.Components2D;

using SimNations.City;


namespace GameCode
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;

        Engine engine = null;

        City2D city = null;

        Version version = Assembly.GetExecutingAssembly().GetName().Version;
        


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            
            city = new City2D(16, 16);
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            engine = new Engine(graphics);
            
            engine.Game = this;
            engine.Fullscreen = false;
            

            engine.Content.Load<Texture2D>("Content/ZonesTest");

            GameScreen screen = new GameScreen();
            engine.PushGameScreen(screen);


            screen.AddComponent(city);
            screen.LoadGameScreen();


            city.LoadSimpleMap("Content/Maps/TestMap.txt");

        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (!this.IsActive)
                return;


            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();


            // Toggle fullscreen mode when user hits the Tab key
            if (Keyboard.GetState().IsKeyDown(Keys.Tab))
                engine.Fullscreen = !engine.Fullscreen;


            base.Update(gameTime);

            engine.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            engine.Draw(gameTime);
            
            engine.DrawString("SimNations - v" +  version.ToString(), new Vector2(5, engine.ScreenHeight - 22), Color.White);

            base.Draw(gameTime);
        }
    }
}
